﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using WebApplication1.Model;

namespace WebApplication1.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class testController : Controller
    {
        private readonly test1context _test1Context1;
        private readonly test2contest _test1Context2;
        public testController(test1context test1Context1, test2contest test1Context2)
        {
            _test1Context1 = test1Context1;
            _test1Context2 = test1Context2;
        }
        [HttpGet]
         public List<t1> testt1()
        {

            return _test1Context1.t1.ToList() ;
        }
        [HttpGet("qq")]
        public List<t2> test2()
        {
            return _test1Context2.t2.ToList();
        }
        [HttpPost("完成一半题目")]
        public int a()
        {
            int[] questions = new int[] { 0, 1, 2, 2, 2, 4, 6, 7, 8, 6 };
            int a = 0;
            int b = questions.Length/2;
            var v = questions.GroupBy(x => x).Select(x => new { c = x.Count() }).OrderByDescending(c=>c.c);
            foreach (var q in v)
            {
                a++;
                if (b - q.c > 0)
                    b = b - q.c;
                else
                {
                    break;
                }
            }
            return a;
        }
        [HttpPost("下载插件")]
        public int a(int n)
        {
            for (int i = 0; i < 100; i++)
            {
                if(Math.Pow(2,i)>n)
                    return i;
            }
            return 0;
        }
    }
}
